package com.bdmc.web.controller.report;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.vo.ReportCheckWorkVo;
import com.bdmc.report.domain.bo.ReportCheckWorkBo;
import com.bdmc.report.service.IReportCheckWorkService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 人员考勤控制器
 *
 * @author bdmc
 * @date 2022-03-11
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/checkWork")
public class ReportCheckWorkController extends BaseController {

    private final IReportCheckWorkService iReportCheckWorkService;

    /**
     * 查询人员考勤列表
     */
    @SaCheckPermission("report:checkWork:list")
    @GetMapping("/list")
    public TableDataInfo<ReportCheckWorkVo> list(@Validated(QueryGroup.class) ReportCheckWorkBo bo, PageQuery pageQuery) {
        return iReportCheckWorkService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出人员考勤列表
     */
    @SaCheckPermission("report:checkWork:export")
    @Log(title = "人员考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportCheckWorkBo bo, HttpServletResponse response) {
        List<ReportCheckWorkVo> list = iReportCheckWorkService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员考勤", ReportCheckWorkVo.class, response);
    }

    /**
     * 获取人员考勤详细信息
     */
    @SaCheckPermission("report:checkWork:query")
    @GetMapping("/{checkWorkId}")
    public AjaxResult<ReportCheckWorkVo> getInfo(@PathVariable("checkWorkId") Long checkWorkId) {
        return AjaxResult.success(iReportCheckWorkService.queryById(checkWorkId));
    }

    /**
     * 新增人员考勤
     */
    @SaCheckPermission("report:checkWork:add")
    @Log(title = "人员考勤", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportCheckWorkBo bo) {
        return toAjax(iReportCheckWorkService.insertByBo(bo));
    }

    /**
     * 修改人员考勤
     */
    @SaCheckPermission("report:checkWork:edit")
    @Log(title = "人员考勤", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportCheckWorkBo bo) {
        return toAjax(iReportCheckWorkService.updateByBo(bo));
    }

    /**
     * 删除人员考勤
     */
    @SaCheckPermission("report:checkWork:remove")
    @Log(title = "人员考勤" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkWorkIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] checkWorkIds) {
        return toAjax(iReportCheckWorkService.deleteWithValidByIds(Arrays.asList(checkWorkIds), true));
    }
}
